package com.ruoyi.web.controller.medicine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.medicine.sjq.domain.HisMedicineFactory;
import com.ruoyi.medicine.sjq.service.IHisMedicineFactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * //
 * //   █████▒█    ██  ▄████▄   ██ ▄█▀       ██████╗ ██╗   ██╗ ██████╗
 * // ▓██   ▒ ██  ▓██▒▒██▀ ▀█   ██▄█▒        ██╔══██╗██║   ██║██╔════╝
 * // ▒████ ░▓██  ▒██░▒▓█    ▄ ▓███▄░        ██████╔╝██║   ██║██║  ███╗
 * // ░▓█▒  ░▓▓█  ░██░▒▓▓▄ ▄██▒▓██ █▄        ██╔══██╗██║   ██║██║   ██║
 * // ░▒█░   ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄       ██████╔╝╚██████╔╝╚██████╔╝
 * //  ▒ ░   ░▒▓▒ ▒ ▒ ░ ░▒ ▒  ░▒ ▒▒ ▓▒       ╚═════╝  ╚═════╝  ╚═════╝
 * //  ░     ░░▒░ ░ ░   ░  ▒   ░ ░▒ ▒░
 * //  ░ ░    ░░░ ░ ░ ░        ░ ░░ ░
 * //           ░     ░ ░      ░  ░
 * //                 ░
 *
 * @author Java song
 * @date 2024/8/28 下午7:32
 * @description
 **/
@RestController
@RequestMapping("medicine/factory")
public class HisMedicineFactoryController extends BaseController {

    @Autowired
    private IHisMedicineFactoryService iHisMedicineFactoryService;

    //多条件查询
    @PreAuthorize("@ss.hasPermi('medicine:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisMedicineFactory hisMedicineFactory) {
        startPage();
        List<HisMedicineFactory> hisMedicineFactories = iHisMedicineFactoryService.selectHisMedicineFactoryList(hisMedicineFactory);
        return getDataTable(hisMedicineFactories);
    }

    //多条件查询
    @PreAuthorize("@ss.hasPermi('medicine:factory:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(HisMedicineFactory hisMedicineFactory) {
        hisMedicineFactory.setStatus("0");
        List<HisMedicineFactory> hisMedicineFactories = iHisMedicineFactoryService.selectHisMedicineFactoryList(hisMedicineFactory);
        return getDataTable(hisMedicineFactories);
    }

    //根据ID查询
    @PreAuthorize("@ss.hasPermi('medicine:factory:query')")
    @GetMapping("/{factoryId}")
    public AjaxResult getInfo(@PathVariable Long factoryId) {
        startPage();
        HisMedicineFactory hisMedicineFactory = iHisMedicineFactoryService.selectHisMedicineFactoryById(factoryId);
        return success(hisMedicineFactory);

    }

    @PreAuthorize("@ss.hasPermi('medicine:factory:add')")
    @Log(title = "生产厂家管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HisMedicineFactory hisMedicineFactory) {
        hisMedicineFactory.setCreateBy(getUsername());
        int i = iHisMedicineFactoryService.insertHisMedicineFactory(hisMedicineFactory);
        return toAjax(i);
    }

    @PreAuthorize("@ss.hasPermi('medicine:factory:edit')")
    @Log(title = "生产厂家管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody HisMedicineFactory hisMedicineFactory) {
        hisMedicineFactory.setUpdateBy(getUsername());
        return toAjax(iHisMedicineFactoryService.updateHisMedicineFactory(hisMedicineFactory));
    }


    @PreAuthorize("@ss.hasPermi('medicine:factory:remove')")
    @Log(title = "生产厂家管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{factoryId}")
    public AjaxResult remove(@PathVariable Long factoryId) {
        return toAjax(iHisMedicineFactoryService.deleteHisMedicineFactory(factoryId));
    }

}
